--[[

	GModRP - Real Garry's Mod Roleplay.
			By Slob187.
		

]]

--To do list:
--Inventory weight limit. (So mass of items carried changes your walk speed as well)
--Admin menu
--In game who-can-own-door with jobs and types of jobs
--Rename jobs to employment
--Fishing rod
--Weapon selection hud
--Custom chatbox
--Custom fire effect
--Make fire system better
--Make the player bleed
--Toilet mod
--Cooking food
--Diseases
--Temperature
--Better medicine system
--Better firehose

--To do later list:
--Resources sysem

--Done list:
--Removed water damage.
--Removed O2 tank item.
--Changed model icons.
--Reduced pay day interval.
--Fixed company system bugs.
--Console commands to change GModRP settings (No more editing txt files and restarting the server)
--Make set random model on spawn
--Adding books
--More player models
--Fix Lua errros when console talking
--Fish food items
--More...

GM.Name			= "GModRP"
GM.Author		= "Slob187"
GM.Email		= "slob187pb@yahoo.com"
GM.Website		= ""

--Sandbox Derived
DeriveGamemode( "sandbox" )


GMRP = {}
GMRP.version = "15beta31"


function GMRP.command( command, func )

	concommand.Add( "gm_rp_"..command, func)
	
end	


include( "configuration.lua" )

CUR = "$"

--citizen models table
citizenmodels = {"models/player/group01/male_02.mdl",
				 "models/player/gman_high.mdl",
				 "models/player/odessa.mdl",
				 "models/player/Kleiner.mdl",
				 "models/player/monk.mdl",
				 "models/player/alyx.mdl",
				 "models/player/eli.mdl",
				 "models/player/Group01/male_07.mdl",
				 "models/player/breen.mdl",
				 "models/player/Group01/Female_01.mdl",
				 "models/player/Group01/male_06.mdl",
				 "models/player/mossman.mdl",
				 "models/player/Group01/Male_01.mdl",
				 "models/player/Group01/Male_05.mdl",
				 "models/player/Group01/male_09.mdl",
				 "models/player/Group01/Female_04.mdl"}

Jobs = {}
Jobs["mayor"] = { 1, "government", 1, 20, {}, {} }
Jobs["judge"] = { 2, "government", 1, 18, {}, {} }
Jobs["policeman"] = { 3, "government", 5, 16, {}, { "gmod_rp_copkeys", "gmod_rp_taser", "gmod_rp_handcuffs", "weapon_stunstick" } }
Jobs["store owner"] = { 4, "commercial", 6, 10, { "food", "drink", "alcohol", "item", "book", "vehicle" }, {} }
Jobs["medic"] = { 5, "publicservices", 5, 12, { "health" }, {} }
Jobs["farmer"] = { 6, "commercial", 3, 6, { "plant" }, {} }
Jobs["firefighter"] = { 7, "publicservices", 3, 11, {}, { "gmod_rp_firehose" } }
Jobs["builder"] = { 8, "commercial", 5, 10, {}, {} }
Jobs["radio broadcaster"] = { 9, "commercial", 5, 10, {}, {} }
Jobs["unemployed"] = { 10, "other", 64, 3, {}, {} }


for k, v in pairs( Jobs ) do

	team.SetUp( Jobs[k][1], k, Color( 90, 111, 142, 225 ) )

end


local pmeta = FindMetaTable( "Player" )
local emeta = FindMetaTable( "Entity" )

function pmeta:IsOutside()

	local trace = {}
	trace.start = self:GetShootPos()
	trace.endpos = trace.start + ( self:GetUp() * 300 )
	trace.filter = self
	local tr = util.TraceLine( trace )

	if !tr.HitWorld && !tr.HitNonWorld then
	
		return true
		
	end
	
	return false

end				


function pmeta:getJob()

	return team.GetName( self:Team() )
	
end	


function pmeta:isJob( name )

	if ( team.GetName( self:Team() ) == name ) then
	
		return true
		
	end
	
	return false
	
end


function pmeta:RedNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring( str ).."', Color( 255, 0, 0 ) )")
		
	else	
	
		Notify( tostring( str ), Color( 255, 0, 0 ) )
		
	end	
	
end


function pmeta:GreenNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring(str).."', Color(0, 255, 0))")
		
	else	
	
		Notify( tostring(str), Color( 0, 255, 0 ) )
		
	end	
	
end	


function pmeta:BlueNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring(str).."', Color(0, 0, 255))")
		
	else	
	
		Notify( tostring(str), Color( 0, 0, 255 ) )
		
	end	
	
end		


function pmeta:GetPlayerEnergy()

	return tonumber( self:GetNWInt( "energy" ) )
	
end	


include("itembase.lua")
if (SERVER) then

	AddCSLuaFile("itembase.lua")
	
end	


for k, v in pairs( file.FindInLua( "GModRP/gamemode/items/*.lua" ) ) do

	include("items/"..v)
	
	if (SERVER) then
	
		AddCSLuaFile("items/"..v)
		
	end
	
end	


function GMRP.UseLimit( p )

	if CurTime() > p:GetNWInt( "NextUse" ) then 
		
		if (SERVER) then
		
			p:SetNWInt( "NextUse", CurTime() + Configuration["useint"] )
			
		end
		
		return true
		
	else

		p:RedNotify( "Please wait "..math.Round( p:GetNWInt( "NextUse" ) - CurTime() ).." second." )
		
		return false
		
	end

end


function emeta:isOwnable()

	local entClass = self:GetClass()

	if string.find( entClass, "door" ) || string.find( entClass, "vehicle" ) then

		return true
	
	end
	
	return false
	
end


function job( name )

	for k, v in pairs( Jobs ) do
	
		if ( name == k ) then
		
			return Jobs[k][1]
			
		end

	end
	
end


function ef( str )

	if ( tostring( str ) == nil ) then return end

	if string.find( str, "'" ) then
	
		return string.gsub( str, "'", "" )
		
	end
	
	return str

end	